package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.mainframeSub.menubar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.Mainframe;

public class MenuFile extends JMenu {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Mainframe mainframe;

	public MenuFile(Mainframe mainframe, String text) {
		super(text);
		this.mainframe = mainframe;
		this.add(new TrayMenuTItem("In System Tray"));
		this.add(new CloseMenuItem("Programm Schliessen"));
	}

	private class CloseMenuItem extends JMenuItem {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private CloseMenuItem(String text) {
			super(text);
			this.addActionListener(new CloseListener());
		}

	}

	private class TrayMenuTItem extends JMenuItem {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private TrayMenuTItem(String text){
			super(text);
			this.addActionListener(new Traylistener());
			
		}
	}
	
	private class Traylistener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			
			MenuFile.this.mainframe.setVisible(false);
			
		}
		
	}

	private class CloseListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {

			System.exit(0);
		}

	}

}
